package com.yutian.endecryption.mock.service;

import com.yutian.endecryption.mock.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;

/**
 * service 基类,获取session和关闭session
 *
 * @author zhang peng yang ming
 * @create 2017-08-01 10:27
 */
public class BaseService <T> {
    private SqlSession session = null;

    public T mapper (Class<T> clazz) {
        session = SqlSessionFactoryUtil.openSqlSession();
        T mapper = session.getMapper(clazz);

        return mapper;
    }

    public void sessionClose () {
        if (session != null) {
            session.commit();
            session.close();
        }
    }
}
